<template>
  <van-submit-bar
    :price="totalPrice * 100"
    button-text="去结算"
    @submit="onSubmit"
    button-color="#1989fa"
  >
    <van-checkbox v-model="allChecked">全选</van-checkbox>
  </van-submit-bar>
</template>

<script setup>
import useCartStore from '@/stores/cart';
import { storeToRefs } from 'pinia';
import { computed, ref } from 'vue';
const cartStore = useCartStore();
const { totalPrice, cartList } = storeToRefs(cartStore);
const onSubmit = () => {
  console.log('筛选对应id和数量去生成订单', cartList.value);
};
const allChecked = computed({
  get() {
    if (!!cartList.value.length) {
      return cartList.value.every((ele) => ele.selected);
    }
  },
  set(val) {
    cartStore.setAll(val);
  },
});
</script>

<style lang="scss" scoped>
:deep(.van-submit-bar__bar) {
  justify-content: space-around;
}
</style>
